package de.lulusoft.anothertorrent.gui.commands;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;

import de.lulusoft.anothertorrent.core.rtorrent.Peer;
import de.lulusoft.anothertorrent.gui.exceptions.ExceptionHandler;

public class PeerSetCommentCommand implements IHandler {
	
	public static final String ID = "de.lulusoft.anothertorrent.gui.commands.PeerSetCommentCommand";
	
	public static final String P_COMMENT = "peerComment";

	@Override
	public void addHandlerListener(IHandlerListener handlerListener) {
	}

	@Override
	public void dispose() {
	}

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		if (event.getTrigger() instanceof Peer)
		{
			Peer p = (Peer)event.getTrigger();
			String val = event.getParameter(P_COMMENT);
			try {
				p.setComment(val);
			} catch (Exception e) {
				ExceptionHandler.alert("Could not set Peer comment", e);
			}
		}
		return null;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

	@Override
	public boolean isHandled() {
		return true;
	}

	@Override
	public void removeHandlerListener(IHandlerListener handlerListener) {
	}

}
